<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{messages.Testpaper}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:form styleClass="jsfcrud_list_form">
                <h:panelGroup rendered="#{teacschoolsubjectController.currentSchool4Teacher.isEmpty()}">
                    <h:outputLabel value="#{messages.Please}#{messages.AskSecretary}"/>
                </h:panelGroup>
                <h:panelGroup rendered="#{!teacschoolsubjectController.currentSchool4Teacher.isEmpty()}">
                    <h:panelGrid columns="2">
                        <h:outputLabel value="#{messages.School}"/>
                        <h:selectOneMenu value="#{schoolController.selected}" required="true" immediate="true">
                            <f:selectItem itemLabel="#{messages.Please}#{messages.Select}"/>
                            <f:selectItems value="#{teacschoolsubjectController.currentSchool4Teacher}"/>
                            <f:ajax render="relatedSubject"/>
                        </h:selectOneMenu>
                        <h:outputLabel value="#{messages.Subject}"/>
                        <h:selectOneMenu value="#{subjectController.selected}" id="relatedSubject" required="true" immediate="true">
                            <f:selectItem itemLabel="#{messages.Please}#{messages.Select}"/>
                            <f:selectItems value="#{teacschoolsubjectController.currentSubject4Teacher}"/>
                            <f:ajax render="relatedTestpaper"/>
                        </h:selectOneMenu>

                        <h:outputLabel value="#{messages.Type}"/>
                        <h:selectOneMenu value="#{testpaperController.typeOfPraOrExam}" id="relatedTestpaper">
                            <f:selectItem itemValue="#{studenttestpaperControllerA.practiceString}" itemLabel="#{messages.Practice}"/>
                            <f:selectItem itemValue="#{studenttestpaperControllerA.examiniationString}" itemLabel="#{messages.Examination}"/>
                        </h:selectOneMenu>
                        <h:commandButton value="1.#{messages.Calculate}#{messages.Score}" action="#{studenttestpaperController.getScore()}"/>
                        <h:commandButton value="2.#{messages.Export}#{messages.Content}" action="#{studenttestpaperController.exportTestPapers()}"/>
                       <!-- <h:commandButton value="#{messages.Export}#{messages.Excel}" action="#{studenttestpaperController.export2Excel()}"/>-->
                        <!--show scores-->
                    </h:panelGrid>
                    <h:panelGrid columns="1">
                        <c:forEach items="#{studenttestpaperController.scoreMap}" var="keyvalue">
                            <h:outputLabel value="#{messages.getString(keyvalue.key)}"/>
                            <h:dataTable value="#{keyvalue.value}" var="item" border="0" 
                                         cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" 
                                         >
                                <!-- show the scores -->
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Id}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.student.name}"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Name1}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.student.secondname}#{item.student.firstname}"/>
                                </h:column>
                                <c:forEach items="#{item.score}" var="score">
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="#{messages.Score}"/>
                                        </f:facet>
                                        <h:outputText value="#{score}"/>
                                    </h:column>
                                </c:forEach>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Average}#{messages.Score}"/>
                                    </f:facet>
                                    <h:outputText value="#{item.averageScore}"/>
                                </h:column>
                            </h:dataTable>
                        </c:forEach>
                    </h:panelGrid>
                </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
